//
//  MqFBMapViewController.m
//  Meiqi
//
//  Created by TwistedFate on 16/5/26.
//  Copyright © 2016年 KFC. All rights reserved.
//

#import "MqFBMapViewController.h"
#import <BaiduMapAPI_Map/BMKMapComponent.h>
#import "MqSingleton.h"
@interface MqFBMapViewController ()<BMKMapViewDelegate>
@property (nonatomic, strong) BMKMapView *mapView;



@end

@implementation MqFBMapViewController


- (void)viewWillAppear:(BOOL)animated
{
    [_mapView viewWillAppear];
    _mapView.delegate = self; // 此处记得不用的时候需要置nil，否则影响内存的释放
}
- (void) viewDidAppear:(BOOL)animated {
//    // 添加一个PointAnnotation
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
    CLLocationCoordinate2D coor;
    coor.latitude = _lat;
    coor.longitude = _lon;
    annotation.coordinate = coor;
    annotation.title = @"车店";
    [_mapView addAnnotation:annotation];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [_mapView viewWillDisappear];
    _mapView.delegate = nil; // 不用时，置nil
}


- (void)viewDidLoad {
    [super viewDidLoad];
 
    //  地图视图
    _mapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
//    [MqSingleton shareData].mapView = _mapView;
    self.view = _mapView;
    
    [_mapView setMapType:BMKMapTypeStandard];//地图样式
    

    //  获取定位信息
    BMKLocationService *locService = [MqSingleton shareData].localService;

    BMKCoordinateRegion region;

    _mapView.showsUserLocation = YES;//显示定位图层BMKCoordinateRegion region;
    region.center.latitude  = locService.userLocation.location.coordinate.latitude;
    region.center.longitude = locService.userLocation.location.coordinate.longitude;
    region.span.latitudeDelta  = 0.2;
    region.span.longitudeDelta = 0.2;
    if (_mapView)
    {
        _mapView.region = region;

    //  在地图上更新位置信息
    [_mapView updateLocationData:locService.userLocation];

    }
}


- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
        return newAnnotationView;
    }
    return nil;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
